package com.ddl.task;
/**
 * @Package org.opencron.server.job
 * @Title: OpencronWatch
 * @author hapic
 * @date 2018/4/8 15:34
 * @version V1.0
 */

import com.ddl.dao.UserFieldMapper;
import com.ddl.pojo.UserField;
import com.ddl.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Descriptions:
 */
@Component
public class FiledTask {
    private static Logger log = LoggerFactory.getLogger(FiledTask.class);
    @Autowired
    UserFieldMapper userFieldMapper;

    @Scheduled(cron = "0 10 0 * * ?")
    public void afterPropertiesSet() throws Exception {
        UserField record = new UserField();
        record.setStatus(0);
        List<UserField> list = userFieldMapper.selectByRecord(record);
        for (UserField userField : list) {
            Integer seedType = 0;
            int days = DateUtil.betweenDayNumber(userField.getCreateTime(), new Date());
            //是种子状态
            if (days < 60) {
                seedType=0;
            }else if (days >= 60 && days < 80) {
                seedType = 1;
            } else if (days >= 80 && days < 130) {
                seedType = 2;
            }else {
                seedType=3;
            }
            if(!seedType.equals(userField.getSeedType())){
                UserField update=new UserField();
                update.setId(userField.getId());
                update.setSeedType(seedType);
                userFieldMapper.updateByPrimaryKeySelective(update);
            }
        }

    }
}
